﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TrainingManagement.web.Infrastructure;
using TrainingManagement.web.Models;
using TrainingManagement.web.Models.ViewModels;
using WebMatrix.WebData;

namespace TrainingManagement.web.Controllers
{
    public class EmployeeController : Controller
    {
        private EmployeeDb _db = new EmployeeDb();

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Create()
        {
            var model = new EmployeeCreateViewModel();
            ViewData["ReportsTo"] = model.ReportsTo;
            return View(model);
        }

        [HttpPost]
        public ActionResult Create(EmployeeCreateViewModel emp)
        {
            WebSecurity.CreateUserAndAccount(emp.UserName, emp.Password, new
                {
                    FirstName = emp.FirstName,
                    LastName = emp.LastName,
                    Email = emp.Email,
                    SmsNumber = emp.SmsNumber,
                    ReportsTo = (int)emp.ReportsTo.SelectedValue,
                    IsActive = true
                });
            return View("Create", new EmployeeCreateViewModel());
        }
    }
}
